1 /* 2 Copyright: Marcelo S. N. Mancini (Hipreme|MrcSnm), 2018 - 2021 3 License: [https://creativecommons.org/licenses/by/4.0/|CC BY-4.0 License]. 4 Authors: Marcelo S. N. Mancini 5 6 Copyright Marcelo S. N. Mancini 2018 - 2021. 7 Distributed under the CC BY-4.0 License. 8 (See accompanying file LICENSE.txt or copy at 9 https://creativecommons.org/licenses/by/4.0/ 10 */ 11 module hip.api; 12 13 14 /** 15 * For building the API some rules must be followed: 16 * 17 * 1: Public Interfaces, Structs and Abstract Classes must always be declared somewhere at hip.api; 18 * 2: Methods will most of the time return an interface when dealing it at scripting time, at release 19 * build, the can return the entire class. 20 * 3: The User API will contain classes named as the same as those defined at the HipremeEngine, so 21 * the user will actually use some aliass. 22 * 4: When building for release (version(DirectCall)), api should publicly import the actual 23 * class definition. 24 * 5: For maintaining consistency, this package may declare some public imports that should be delegated 25 * to the actual API when that API is an aliased import. 26 */ 27 28 public import hip.api.impl; 29 public import hip.api.config; 30 31 32 enum HipAssetLoadStrategy 33 { 34 loadAll 35 } 36 37 version(ScriptAPI) version = UseExternalScene; 38 39 ///Most important functions here 40 version(UseExternalScene) 41 { 42 alias hipDestroyFn = extern(System) void function(Object); 43 __gshared hipDestroyFn hipDestroy; 44 } 45 46 47 mixin template HipEngineMain(alias StartScene, HipAssetLoadStrategy strategy = HipAssetLoadStrategy.loadAll) 48 { 49 immutable string ScriptModules = import("scriptmodules.txt"); 50 pragma(msg, ScriptModules); 51 version(UseExternalScene) 52 { 53 __gshared AScene _exportedScene; 54 version(Windows) 55 { 56 import core.sys.windows.dll; 57 mixin SimpleDllMain; 58 } 59 export extern(System) AScene HipremeEngineGameInit() 60 { 61 import hip.api; 62 import hip.api.systems.system_binding; 63 import hip.api.game.game_binding; 64 import core.runtime; 65 import hip.api.internal:initializeHip; 66 67 rt_init(); 68 initializeHip(); 69 initConsole(); 70 HipFS.initFS(); 71 initG2D(); 72 HipAudio.initAudio(); 73 HipInput.initInput(); 74 HipDefaultAssets.initGlobalAssets(); 75 HipAssetManager.initAssetManager(); 76 initTimerAPI(); 77 initGameAPI(); 78 79 mixin LoadAllAssets!(ScriptModules); 80 loadReferenced(); 81 82 return _exportedScene = new StartScene(); 83 } 84 export extern(System) void HipremeEngineGameDestroy() 85 { 86 if(_exportedScene) 87 { 88 _exportedScene.dispose(); 89 destroy(_exportedScene); 90 } 91 _exportedScene=null; 92 } 93 } 94 else 95 { 96 export AScene HipremeEngineMainScene() 97 { 98 mixin LoadAllAssets!(ScriptModules); 99 loadReferenced(); 100 return new StartScene(); 101 } 102 } 103 }